Asteroids Game


This game looks very complex but follows simple rules. The main objective is to learn about <Procedure> blocks.


Procedures allow programming rules to be made for individual agents or everyone but not be placed in the <Run> sections. A link block is placed in the <Run> section directing you to the procedure found elsewhere in the window. This allows for better organization of programming.

In the <Forever> block you have links to procedures for the Fighter-Movement/Firing, Asteroid-Asteroid Motion, and Projectile-Projectile Motion.
You also have a procedure in <Collisions> for Asteroids-Asteroid break down.
These procedures are found in the window sections for the agents involved.

Asteroid_Setup_and_Collisions_2.jpg

There is one procedure for Fighter-Movement/Firing (found in the Fighter Window Section).
You have the movement commands you are familiar with.
The last coding section directs to only allow 4 projectiles on the screen at a time and to allow an agent to be hatched.
Hatching involved another agent being created. We change the agent being “hatched” from a Fighter to a Projectile using <breed: projectile> as well as size and color.

Fighter_Movement-Firing_Procedure.jpg

There is only one procedure for the Projectile.
The projectiles move forward at a rate of 5. If the x and y coordinates are less than or equal to -49 or greater than or equal to 49, the projectile will die and disappear off Spaceland. This is to keep projectiles from bouncing forever off walls.

Projectile-Projectile_Motion.jpg

There are two procedures for the Asteroids.
The first procedure is the motion of each Asteroid.
The second procedure states that if the size of an Asteroid is larger than 3 (when hit by projectile in collisions) then hatch another Asteroid, subtract its size by 2, and have it move in a random direction left from 0-360 degrees. If the size is smaller than 3, the asteroid dies and disappears off of Spaceland (when hit by a projectile). This is to keep smaller and smaller asteroids from being hatched that are too small to see from destroying your fighter.

Asteroid_Motion_and_Asteroid_Break_Procedure.jpg

Try the game. There is a bug in the Starlogo TNG program. If the game crashes, press the <Forever> block first and then the <Setup> block repeatedly until the game starts normally.